package ModelLayer;
import java.util.ArrayList;


/**
 * Write a description of class Customer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Customer extends Person
{   
    private String group;
    private ArrayList<Lease> leases;
    private ArrayList<Order> orders;
    /**
     * Constructor for objects of class Customer
     * It assignes provided data to attributes of Customer class,
     * both those generic of this class as well as those inherited from Person class
     */
    public Customer(String i_id, String i_name, String i_phone_nr, String i_address, String i_postal_code, String i_city, String i_group, ArrayList<String> lease_ids, ArrayList<String> order_ids)
    {
        super(i_id, i_name, i_phone_nr, i_address, i_postal_code, i_city);
        group = i_group;
        leases = new ArrayList<>();
        orders = new ArrayList<>();
        fill_leases(lease_ids);
        fill_orders(order_ids);
        
    }

    /**********************************************************************************GETTERS**********************************************************************************************/
    
    /**
     * Returns Customer's group.
     */
    public String get_group()
    {
        return group;
    }
    
    /**********************************************************************************SETTERS**********************************************************************************************/
    
    /**
     * Changes Customer's group.
     */
    public void set_group(String input)
    {
        group = input;
    }
    
    /**********************************************************************************OTHER METHODS**********************************************************************************************/
    
    public String give_string_data()
    {
        String temp1="";
        boolean first = true;
        for (Lease lease:leases)
        {
            if(first)
            {
                temp1 += lease.get_id();
                first = false;
            }
            else
            {
                temp1 += " " + lease.get_id();
            }
        }
        first = true;
        String temp2 = "";
        for (Order order : orders)
        {
            if(first)
            {
                temp2 += order.get_id();
                first = false;
            }
            else
            {
                temp2 += " " + order.get_id();
            }
        }
        
        return super.give_string_data() + String.format("\t%s\t%s\t%s", temp1, temp2, group);
    }
    
    public String printable()
    {
        return super.printable() + String.format("Group:\t\t\t\t%s", group);
    }
    
    private void fill_orders(ArrayList<String> ids)
    {
        if(!(ids.contains("")))
        {
            for(String id : ids)
            {
                add_order(id);
            }
        }
    }
    
    private void fill_leases(ArrayList<String> ids)
    {
        if(!(ids.contains("")))
        {
            for(String id : ids)
            {
                add_lease(id);
            }
        }
    }
    
    public void add_order(String id)
    {
        orders.add(OrderCollection.find_by_id(id));
    }
    
    public void add_lease(String id)
    {
        leases.add(LeaseCollection.find_by_id(id));
    }
}
